<?php

namespace Lib;

class Log
{
    private static function writeLog(string $msg,string $logLevel = 'error')
    {
        $ymd = date('Y-m-d');
        $logFilePath = EASYSWOOLE_ROOT . '/Log/' . $ymd . '-' . $logLevel . '.log';
        if (!file_exists($logFilePath)) {
            touch($logFilePath);
        }
        $date = date('Y-m-d H:i:s');
        $str = "[{$date}][{$logLevel}]:{$msg}\n";
        file_put_contents($logFilePath,"{$str}",FILE_APPEND|LOCK_EX);
        return $str;
    }

    public static function error($msg)
    {
        return self::writeLog($msg, 'error');
    }

    public static function info($msg)
    {
        return self::writeLog($msg, 'info');
    }

    public static function notice($msg)
    {
        return self::writeLog($msg, 'notice');
    }

    public static function warning($msg)
    {
        return self::writeLog($msg, 'warning');
    }
}
